import axios from 'axios'
import { Notification } from 'element-ui'
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API, // url = base url + request url
  // withCredentials: true, // send cookies when cross-domain requests
  timeout: 60000 // request timeout
})
service.interceptors.response.use(response => {
  // console.log("TCL: response", response)
  const res = response.data
  if (res.error_code === 888) {
    Notification({
      title: res.message || 'error',
      type: 'error'
    })
    return Promise.reject(res.message || 'error')
  }
  return res
}, error => {
  Notification({
    title: error.message,
    type: 'error'
  })
  return Promise.reject(error)
})
export default service
